package com.huawei.appgallery.forum.option.post.view;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Handler;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.bqx;
import o.bqy;
import o.bsp;
import o.btg;
import o.btu;
import o.btw;
import o.byc.f;
import o.byc.j;
import o.byf;
import o.byh;
import o.byl;
import o.byq;
import o.byr;
import o.byu;
import o.byv;
import o.epv;
import o.CollectCheck;
import o.eqx;

public class RichTextEditor extends ScrollView implements btg {
    private OnFocusChangeListener ʻ;
    private byu ʻॱ;
    private OnKeyListener ʼ;
    private OnFocusChangeListener ʽ;
    private LinearLayout ˊ;
    private OnFocusChangeListener ˊॱ;
    private int ˋ;
    private boolean ˋॱ;
    private final int ˎ;
    private LayoutInflater ˏ;
    private boolean ˏॱ;
    private EditText ͺ;
    private int ॱ;
    private LinearLayout ॱˊ;
    private byq ॱˋ;
    private Handler ॱˎ;
    private OnKeyListener ॱॱ;
    private EditText ॱᐝ;
    private OnKeyListener ᐝ;
    private byr ᐝॱ;

    class a implements TextWatcher {
        private boolean ʽ = false;
        final /* synthetic */ RichTextEditor ˊ;
        int ˋ;
        int ˎ;
        private String ˏ = "";
        private EditText ॱ;

        a(RichTextEditor richTextEditor, EditText editText) {
            this.ˊ = richTextEditor;
            this.ॱ = editText;
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            this.ˏ = charSequence.toString();
            this.ʽ = btw.ॱ(this.ॱ, i);
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            this.ˊ.ॱ = this.ˊ.ॱ + (charSequence.length() - this.ˏ.length());
            if (this.ʽ) {
                btw.ˊ(i, this, this.ॱ);
            }
        }

        public void afterTextChanged(Editable editable) {
            this.ˎ = this.ॱ.getSelectionStart();
            this.ˋ = this.ॱ.getSelectionEnd();
            if (((double) this.ˊ.ॱ) >= 9000.0d) {
                if (this.ˊ.ॱ > 10000) {
                    this.ॱ.removeTextChangedListener(this);
                    try {
                        editable.delete(this.ˎ - (this.ˊ.ॱ - 10000), this.ˋ);
                    } catch (Exception e) {
                        bqx.ॱ("RichTextEditor", "delete string error");
                    }
                    this.ॱ.setTextKeepState(editable);
                    this.ॱ.addTextChangedListener(this);
                    this.ˊ.ॱ = 10000;
                }
                this.ˊ.ˏ(true, this.ˊ.ॱ);
            } else {
                this.ˊ.ˏ(false, this.ˊ.ॱ);
            }
            this.ˊ.ʻ();
            if (TextUtils.isEmpty(editable.toString()) && this.ˊ.ˊ.getChildCount() > 1) {
                int indexOfChild = this.ˊ.ˊ.indexOfChild(this.ॱ);
                if (indexOfChild == 0) {
                    this.ˊ.ˊ(this.ॱ);
                    this.ˊ.ˊ(indexOfChild, true);
                } else if (indexOfChild > 0) {
                    this.ˊ.ˊ(this.ॱ);
                    this.ˊ.ˊ(indexOfChild - 1, false);
                } else {
                    bqx.ˊ("RichTextEditor", "index < 0");
                }
            }
        }
    }

    class c implements TextWatcher {
        private LinearLayout ˊ;
        final /* synthetic */ RichTextEditor ˎ;

        c(RichTextEditor richTextEditor, EditText editText) {
            this.ˎ = richTextEditor;
            ViewParent parent = editText.getParent();
            if (parent instanceof LinearLayout) {
                this.ˊ = (LinearLayout) parent;
            }
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void afterTextChanged(Editable editable) {
            if (this.ˊ != null && editable.toString().length() > 0) {
                int indexOfChild = this.ˎ.ˊ.indexOfChild(this.ˊ);
                if (indexOfChild == 0) {
                    this.ˎ.ˋ(indexOfChild, editable.toString()).requestFocus();
                } else {
                    View childAt = this.ˎ.ˊ.getChildAt(indexOfChild - 1);
                    if (childAt instanceof LinearLayout) {
                        this.ˎ.ˋ(indexOfChild, editable.toString()).requestFocus();
                    } else if (childAt instanceof EditText) {
                        EditText editText = (EditText) childAt;
                        editText.requestFocus();
                        Editable text = editText.getText();
                        text.insert(text.length(), editable.toString());
                        editText.setSelection(text.length());
                    } else {
                        bqx.ˊ("RichTextEditor", "invalid tempView");
                    }
                }
                editable.delete(0, editable.length());
            }
        }
    }

    class d implements TextWatcher {
        private LinearLayout ˊ;
        final /* synthetic */ RichTextEditor ˎ;

        d(RichTextEditor richTextEditor, EditText editText) {
            this.ˎ = richTextEditor;
            ViewParent parent = editText.getParent();
            if (parent instanceof LinearLayout) {
                this.ˊ = (LinearLayout) parent;
            }
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void afterTextChanged(Editable editable) {
            if (this.ˊ != null && editable.toString().length() > 0) {
                int indexOfChild = this.ˎ.ˊ.indexOfChild(this.ˊ);
                if (this.ˎ.ˊ.getChildCount() - 1 > indexOfChild) {
                    View childAt = this.ˎ.ˊ.getChildAt(indexOfChild + 1);
                    if (childAt instanceof EditText) {
                        EditText editText = (EditText) childAt;
                        editText.requestFocus();
                        editText.getText().insert(0, editable.toString());
                        editText.setSelection(editable.toString().length());
                    } else if (childAt instanceof LinearLayout) {
                        this.ˎ.ˋ(indexOfChild + 1, editable.toString()).requestFocus();
                    } else {
                        bqx.ˊ("RichTextEditor", "invalid tempView");
                    }
                } else {
                    this.ˎ.ˋ(indexOfChild + 1, editable.toString()).requestFocus();
                }
                editable.delete(0, editable.length());
            }
        }
    }

    public void ˏ(List<byf> list) {
        if (!ॱ((List) list)) {
            this.ˊ.removeAllViews();
            int i = 0;
            for (int i2 = 0; i2 < list.size(); i2++) {
                byf o_byf = (byf) list.get(i2);
                if (o_byf != null) {
                    if (o_byf.ॱ() == 2) {
                        if (o_byf.ˊ() == null) {
                            bqx.ॱ("RichTextEditor", "card link data is null");
                        } else {
                            ˊ(i, o_byf.ˊ());
                            i++;
                        }
                    } else if (o_byf.ॱ() == 0) {
                        if (o_byf.ˎ() == null) {
                            bqx.ॱ("RichTextEditor", "imagedata is null");
                        } else {
                            ˋ(i, o_byf.ˎ());
                            i++;
                        }
                    } else if (o_byf.ॱ() == 1) {
                        EditText ˋ = ˋ(i, btu.ॱ(getContext(), o_byf.ˏ(), btu.ॱ()));
                        ˋ.setSelection(ˋ.getText().length());
                        i++;
                    } else {
                        bqx.ॱ("RichTextEditor", "unknow editdata type");
                    }
                }
            }
        }
        if (this.ˊ.getChildCount() == 0) {
            ˋ(0, (CharSequence) "");
        }
        ˊ(0, true);
        ʻ();
    }

    private boolean ॱ(List<byf> list) {
        if (CollectCheck.isEmpty((List) list)) {
            bqx.ˊ("RichTextEditor", "contentList is empty");
            return true;
        } else if (list.size() != 1 || ((byf) list.get(0)).ॱ() != 1 || !TextUtils.isEmpty(((byf) list.get(0)).ˏ())) {
            return false;
        } else {
            bqx.ˊ("RichTextEditor", "content is empty");
            return true;
        }
    }

    public void setOnImageNumberListener(byu o_byu) {
        this.ʻॱ = o_byu;
    }

    public void setOnCharNumberListener(byq o_byq) {
        this.ॱˋ = o_byq;
    }

    public void setOnContentIsEmptyListener(byr o_byr) {
        this.ᐝॱ = o_byr;
    }

    public RichTextEditor(Context context) {
        this(context, null, 0);
    }

    public RichTextEditor(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public RichTextEditor(Context context, AttributeSet attributeSet, int i) {
        int ˊ;
        super(context, attributeSet, i);
        this.ˋ = 0;
        this.ॱ = 0;
        this.ˋॱ = false;
        this.ˏॱ = false;
        this.ॱˎ = new b(this, null);
        this.ˏ = LayoutInflater.from(context);
        this.ˊ = new LinearLayout(context);
        this.ˊ.setOrientation(1);
        addView(this.ˊ, new LayoutParams(-1, -2));
        this.ॱॱ = new 1(this);
        this.ʼ = new 4(this);
        this.ᐝ = new 2(this);
        this.ʽ = new 3(this);
        this.ʻ = new 5(this);
        this.ˊॱ = new 10(this);
        ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
        View ॱ = ॱ(getResources().getString(j.ʻ));
        this.ˊ.addView(ॱ, layoutParams);
        this.ͺ = ॱ;
        if (azb.ˎ(getContext())) {
            ˊ = azb.ˊ(getContext());
        } else {
            ˊ = azb.ʻ(getContext());
        }
        this.ˎ = ˊ;
    }

    public void ˋ(byl o_byl) {
        if (this.ˋ >= 30) {
            ˏ(true);
            bqx.ˊ("RichTextEditor", "imgNumber reach limit");
        } else if (this.ˏॱ && this.ॱˊ != null) {
            ˋ(this.ˊ.indexOfChild(this.ॱˊ), o_byl);
        } else if (!this.ˋॱ || this.ॱˊ == null) {
            CharSequence subSequence = this.ͺ.getText().subSequence(0, this.ͺ.getText().toString().length());
            int selectionStart = this.ͺ.getSelectionStart();
            CharSequence subSequence2 = subSequence.subSequence(0, selectionStart);
            int indexOfChild = this.ˊ.indexOfChild(this.ͺ);
            subSequence = subSequence.subSequence(selectionStart, subSequence.length());
            if (TextUtils.isEmpty(subSequence2)) {
                ˊ(this.ͺ);
                if (!TextUtils.isEmpty(subSequence)) {
                    this.ॱ -= subSequence.length();
                    if (this.ॱ < 0) {
                        this.ॱ = 0;
                    }
                }
            } else {
                this.ͺ.setText(subSequence2);
                indexOfChild++;
            }
            if (!TextUtils.isEmpty(subSequence)) {
                ˋ(indexOfChild, subSequence);
            }
            ˋ(indexOfChild, o_byl);
        } else {
            ˋ(this.ˊ.indexOfChild(this.ॱˊ) + 1, o_byl);
        }
    }

    private void ˋ(int i) {
        View childAt = this.ˊ.getChildAt(i - 1);
        View childAt2 = this.ˊ.getChildAt(i);
        if ((childAt instanceof EditText) && (childAt2 instanceof EditText)) {
            EditText editText = (EditText) childAt;
            childAt2 = (EditText) childAt2;
            CharSequence subSequence = editText.getText().subSequence(0, editText.getText().toString().length());
            CharSequence subSequence2 = childAt2.getText().subSequence(0, childAt2.getText().toString().length());
            Object spannableStringBuilder = new SpannableStringBuilder();
            if (subSequence2.length() > 0) {
                spannableStringBuilder.append(subSequence).append(subSequence2);
                this.ॱ -= subSequence2.length();
                if (this.ॱ < 0) {
                    this.ॱ = 0;
                }
            } else {
                spannableStringBuilder.append(subSequence);
            }
            ˊ(childAt2);
            editText.setText(spannableStringBuilder);
            editText.requestFocus();
            editText.setSelection(subSequence.length(), subSequence.length());
        }
        if (this.ˊ.getChildCount() == 1) {
            childAt = this.ˊ.getChildAt(0);
            if (childAt instanceof EditText) {
                ((EditText) childAt).setHint(getResources().getString(j.ʻ));
            }
        }
    }

    private void ˊ(View view) {
        this.ˊ.removeView(view);
        ˋ();
    }

    private void ˎ(View view, int i) {
        ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
        if (i > 0) {
            layoutParams.topMargin = epv.ˋ(getContext(), 8);
        }
        this.ˊ.addView(view, i, layoutParams);
        ˋ();
    }

    private void ˋ() {
        int childCount = this.ˊ.getChildCount();
        if (childCount > 0) {
            View childAt = this.ˊ.getChildAt(0);
            if (childAt != null) {
                ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
                layoutParams.topMargin = 0;
                childAt.setLayoutParams(layoutParams);
            } else {
                bqx.ॱ("RichTextEditor", "resetFirstMargin error");
            }
            int i = 1;
            while (i < childCount) {
                View childAt2 = this.ˊ.getChildAt(i);
                if (childAt2 != null) {
                    ViewGroup.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-1, -1);
                    if ("clink".equals(childAt2.getTag()) || "clink".equals(this.ˊ.getChildAt(i - 1).getTag())) {
                        layoutParams2.topMargin = epv.ˋ(getContext(), 4);
                    } else {
                        layoutParams2.topMargin = epv.ˋ(getContext(), 8);
                    }
                    childAt2.setLayoutParams(layoutParams2);
                } else {
                    bqx.ॱ("RichTextEditor", "resetFirstMargin error");
                }
                i++;
            }
        }
    }

    private EditText ˋ(int i, CharSequence charSequence) {
        View ॱ = ॱ(getResources().getString(j.ʻ));
        ॱ.setText(charSequence);
        ˎ(ॱ, i);
        return ॱ;
    }

    private EditText ॱ(String str) {
        View inflate = this.ˏ.inflate(f.ˏ, null);
        if (inflate instanceof DeletableEditText) {
            DeletableEditText deletableEditText = (DeletableEditText) inflate;
            deletableEditText.setOnKeyListener(this.ॱॱ);
            deletableEditText.setTag("string");
            deletableEditText.setHint(str);
            deletableEditText.setSelectionChangedListener(this);
            deletableEditText.setOnFocusChangeListener(this.ʽ);
            deletableEditText.addTextChangedListener(new a(this, deletableEditText));
            return deletableEditText;
        }
        bqx.ॱ("RichTextEditor", "createEditText failed");
        return new EditText(getContext());
    }

    private void ˋ(int i, byl o_byl) {
        View ʼ = ʼ();
        EditText editText = (EditText) ʼ.findViewById(o.byc.d.ᐝॱ);
        editText.setOnKeyListener(this.ʼ);
        editText.setOnFocusChangeListener(this.ʻ);
        editText.addTextChangedListener(new d(this, editText));
        editText.requestFocus();
        EditText editText2 = (EditText) ʼ.findViewById(o.byc.d.ʽ);
        editText2.setOnKeyListener(this.ᐝ);
        editText2.setOnFocusChangeListener(this.ˊॱ);
        editText2.addTextChangedListener(new c(this, editText2));
        ʼ.findViewById(o.byc.d.ॱ).setOnClickListener(new byv(editText2));
        this.ॱᐝ = editText;
        ImageView imageView = (DataImageView) ʼ.findViewById(o.byc.d.ॱॱ);
        if (o_byl.ʼ()) {
            eqx.ˏ(imageView, o_byl.ˏ(), "image_default_icon");
        } else {
            eqx.ˏ(imageView, o_byl.ʽ(), "image_default_icon");
        }
        imageView.setUploadImageData(o_byl);
        ˎ(ʼ, i);
        this.ॱˎ.sendEmptyMessageDelayed(1004, 50);
        this.ˋ++;
        ʻ();
        ˏ(this.ˋ >= 30);
    }

    private void ˊ(int i, byh o_byh) {
        View ᐝ = ᐝ();
        EditText editText = (EditText) ᐝ.findViewById(o.byc.d.ᐝॱ);
        editText.setOnKeyListener(this.ʼ);
        editText.setOnFocusChangeListener(this.ʻ);
        editText.addTextChangedListener(new d(this, editText));
        editText.requestFocus();
        EditText editText2 = (EditText) ᐝ.findViewById(o.byc.d.ʽ);
        editText2.setOnKeyListener(this.ᐝ);
        editText2.setOnFocusChangeListener(this.ˊॱ);
        editText2.addTextChangedListener(new c(this, editText2));
        ᐝ.findViewById(o.byc.d.ॱ).setOnClickListener(new byv(editText2));
        ᐝ.findViewById(o.byc.d.ˊ).setOnClickListener(new byv(editText));
        this.ॱᐝ = editText;
        PostCardLinkView postCardLinkView = (PostCardLinkView) ᐝ.findViewById(o.byc.d.ˋ);
        if (postCardLinkView != null) {
            postCardLinkView.setLayoutParams(ˊ(o_byh, postCardLinkView));
            postCardLinkView.setCardLinkDate(o_byh);
            postCardLinkView.setRootLayoutClickable(false);
        }
        ˎ(ᐝ, i);
    }

    private LinearLayout ʼ() {
        View inflate = this.ˏ.inflate(f.ˋ, null);
        if (!(inflate instanceof LinearLayout)) {
            return new LinearLayout(getContext());
        }
        LinearLayout linearLayout = (LinearLayout) inflate;
        linearLayout.setTag("img");
        return linearLayout;
    }

    private LinearLayout ᐝ() {
        View inflate = this.ˏ.inflate(f.ॱ, null);
        if (!(inflate instanceof LinearLayout)) {
            return new LinearLayout(getContext());
        }
        LinearLayout linearLayout = (LinearLayout) inflate;
        linearLayout.setTag("clink");
        return linearLayout;
    }

    private void ˏ(EditText editText) {
        int selectionStart = editText.getSelectionStart();
        int indexOfChild = this.ˊ.indexOfChild(editText);
        if (selectionStart == 0 && indexOfChild > 0) {
            View childAt = this.ˊ.getChildAt(indexOfChild - 1);
            if (childAt instanceof LinearLayout) {
                ((EditText) ((LinearLayout) childAt).findViewById(o.byc.d.ᐝॱ)).requestFocus();
            }
        }
    }

    private void ˏ(View view) {
        int indexOfChild = this.ˊ.indexOfChild(view);
        ˊ(view);
        this.ˋ--;
        ˏ(this.ˋ >= 30);
        ʻ();
        if (indexOfChild == 0) {
            if (this.ˊ.getChildCount() == 0) {
                ˋ(0, (CharSequence) "").requestFocus();
            } else {
                ˊ(indexOfChild, true);
            }
        } else if (indexOfChild <= this.ˊ.getChildCount() - 1 && (this.ˊ.getChildAt(indexOfChild - 1) instanceof EditText) && (this.ˊ.getChildAt(indexOfChild) instanceof EditText)) {
            ˋ(indexOfChild);
        } else {
            ˊ(indexOfChild - 1, false);
        }
    }

    private void ˊ(int i, boolean z) {
        if (i < 0 || this.ˊ.getChildCount() == 0 || i > this.ˊ.getChildCount() - 1) {
            bqx.ॱ("RichTextEditor", "invalid index:" + i);
            return;
        }
        View childAt = this.ˊ.getChildAt(i);
        if (childAt instanceof EditText) {
            EditText editText = (EditText) childAt;
            editText.requestFocus();
            editText.setSelection(z ? 0 : editText.getText().length());
        } else if (childAt instanceof LinearLayout) {
            ((EditText) childAt.findViewById(z ? o.byc.d.ʽ : o.byc.d.ᐝॱ)).requestFocus();
        } else {
            bqx.ॱ("RichTextEditor", "resetFocus failed");
        }
    }

    public List<byf> ˏ() {
        List<byf> arrayList = new ArrayList();
        int childCount = this.ˊ.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = this.ˊ.getChildAt(i);
            if ("string".equals(childAt.getTag())) {
                arrayList.add(new byf(((EditText) childAt).getText().toString()));
            } else if ("img".equals(childAt.getTag())) {
                arrayList.add(new byf(((DataImageView) childAt.findViewById(o.byc.d.ॱॱ)).ˏ()));
            } else if ("clink".equals(childAt.getTag())) {
                arrayList.add(new byf(((PostCardLinkView) childAt.findViewById(o.byc.d.ˋ)).ˏ()));
            } else {
                bqx.ॱ("RichTextEditor", "getContentDataListContent invalid itemView");
            }
        }
        return arrayList;
    }

    public String ˊ(boolean z) {
        StringBuilder stringBuilder = new StringBuilder();
        int childCount = this.ˊ.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = this.ˊ.getChildAt(i);
            if ("string".equals(childAt.getTag())) {
                EditText editText = (EditText) childAt;
                if (z) {
                    stringBuilder.append(btu.ˏ(editText).toString());
                } else {
                    stringBuilder.append(editText.getText().toString());
                }
            } else if ("img".equals(childAt.getTag())) {
                stringBuilder.append("[img]").append(((DataImageView) childAt.findViewById(o.byc.d.ॱॱ)).ˏ().ˏॱ()).append("[/img]");
            } else if ("clink".equals(childAt.getTag())) {
                byh ˏ = ((PostCardLinkView) childAt.findViewById(o.byc.d.ˋ)).ˏ();
                stringBuilder.append("[clink=").append(ˏ.ˎ()).append("_").append(ˏ.ˋ()).append("]").append(ˏ.ॱ()).append("[/clink]");
            } else {
                bqx.ॱ("RichTextEditor", "getContentString invalid itemView");
            }
        }
        return stringBuilder.toString().replaceAll("[\\t\\n\\r]", "[br]");
    }

    private boolean ʽ() {
        return ˊ(false).replace("[br]", "").trim().isEmpty();
    }

    public String ॱ() {
        int i = 0;
        List arrayList = new ArrayList();
        int childCount = this.ˊ.getChildCount();
        for (int i2 = 0; i2 < childCount; i2++) {
            View childAt = this.ˊ.getChildAt(i2);
            if ("img".equals(childAt.getTag())) {
                DataImageView dataImageView = (DataImageView) childAt.findViewById(o.byc.d.ॱॱ);
                if (dataImageView.ˏ() != null && dataImageView.ˏ().ˏॱ() > -1) {
                    arrayList.add(String.valueOf(dataImageView.ˏ().ˏॱ()));
                }
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        while (i < arrayList.size()) {
            stringBuilder.append((String) arrayList.get(i));
            if (i < arrayList.size() - 1) {
                stringBuilder.append(",");
            }
            i++;
        }
        return stringBuilder.toString();
    }

    public void setEnable(boolean z) {
        int childCount = this.ˊ.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = this.ˊ.getChildAt(i);
            EditText editText;
            if (childAt instanceof EditText) {
                editText = (EditText) childAt;
                editText.setFocusable(z);
                editText.setFocusableInTouchMode(z);
            } else if (childAt instanceof LinearLayout) {
                EditText editText2 = (EditText) childAt.findViewById(o.byc.d.ʽ);
                editText = (EditText) childAt.findViewById(o.byc.d.ᐝॱ);
                editText2.setFocusable(z);
                editText2.setFocusableInTouchMode(z);
                editText.setFocusable(z);
                editText.setFocusableInTouchMode(z);
            } else {
                bqx.ॱ("RichTextEditor", "setEnable invalid itemView");
            }
        }
        if (!z) {
            this.ॱˎ.sendEmptyMessage(1005);
        }
    }

    private void ʻ() {
        if (this.ᐝॱ == null) {
            bqx.ॱ("RichTextEditor", "onContentIsEmptyListener == null");
        } else if (ʽ()) {
            this.ᐝॱ.ˏ();
        } else {
            this.ᐝॱ.ˋ();
        }
    }

    private void ˏ(boolean z) {
        if (this.ʻॱ == null) {
            bqx.ॱ("RichTextEditor", "onImageNumberListener == null");
        } else if (z) {
            this.ʻॱ.aa_();
        } else {
            this.ʻॱ.ᐝ();
        }
    }

    public List<byl> ˎ() {
        List<byl> arrayList = new ArrayList();
        int childCount = this.ˊ.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = this.ˊ.getChildAt(i);
            if ("img".equals(childAt.getTag())) {
                arrayList.add(((DataImageView) childAt.findViewById(o.byc.d.ॱॱ)).ˏ());
            }
        }
        return arrayList;
    }

    private void ˏ(boolean z, int i) {
        if (this.ॱˋ == null) {
            bqx.ॱ("RichTextEditor", "onCharNumberListener == null");
        } else if (z) {
            this.ॱˋ.ˏ(i);
        } else {
            this.ॱˋ.ˎ();
        }
    }

    public void ˊ(View view, int i, int i2) {
        if (view instanceof EditText) {
            btw.ˋ(i, i2, (EditText) view);
        }
    }

    public void ॱ(int i) {
        if (16908322 == i) {
            ClipboardManager clipboardManager = (ClipboardManager) bqy.ˋ().ˏ().getSystemService("clipboard");
            clipboardManager.setPrimaryClip(ClipData.newPlainText("span text", clipboardManager.getPrimaryClip().getItemAt(0).getText().toString()));
        }
    }

    public void ˊ() {
        if (this.ˊ == null) {
            bqx.ॱ("RichTextEditor", "request click error, allLayout is null");
        } else {
            ˊ(this.ˊ.getChildCount() - 1, false);
        }
    }

    private void ॱॱ() {
        if (this.ॱᐝ != null) {
            this.ॱᐝ.requestFocus();
            Object systemService = this.ॱᐝ.getContext().getSystemService("input_method");
            if (systemService instanceof InputMethodManager) {
                ((InputMethodManager) systemService).showSoftInput(this.ॱᐝ, 0);
            }
        }
    }

    private void ॱˊ() {
        Object systemService = getContext().getSystemService("input_method");
        if (systemService instanceof InputMethodManager) {
            ((InputMethodManager) systemService).hideSoftInputFromWindow(getWindowToken(), 0);
        }
    }

    protected void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        for (int i = 0; i < this.ˊ.getChildCount(); i++) {
            View childAt = this.ˊ.getChildAt(i);
            if (childAt instanceof LinearLayout) {
                PostCardLinkView postCardLinkView = (PostCardLinkView) ((LinearLayout) childAt).findViewById(o.byc.d.ˋ);
                if (postCardLinkView != null) {
                    postCardLinkView.setLayoutParams(ˊ(postCardLinkView.ˏ(), postCardLinkView));
                    postCardLinkView.setBackground(getContext().getDrawable(o.byc.c.ˋ));
                }
            }
        }
    }

    private LayoutParams ˊ(byh o_byh, PostCardLinkView postCardLinkView) {
        LayoutParams layoutParams = (LayoutParams) postCardLinkView.getLayoutParams();
        if (bsp.ˏ(postCardLinkView.ˊ(), o_byh.ॱ()) > (((azb.ॱ(getContext()) - (this.ˎ * 2)) - (getContext().getResources().getDimensionPixelSize(o.byc.a.ʽ) * 2)) - getContext().getResources().getDimensionPixelSize(o.byc.a.ˎ)) - getContext().getResources().getDimensionPixelSize(o.byc.a.ˊ)) {
            layoutParams.width = (azb.ॱ(getContext()) - (this.ˎ * 2)) - 4;
        } else {
            layoutParams.width = -2;
        }
        return layoutParams;
    }
}
